<template>
	<view>
		登录页面
		<uv-input placeholder="请输入账号" border="surround" v-model="loginForm.username"></uv-input>
		<uv-input type="password" placeholder="请输入密码" border="surround" v-model="loginForm.password"></uv-input>
		<uv-button type="primary" text="登录" @click="login"></uv-button>
	</view>
</template>

<script setup>
	import { loginApi } from '@/api/user.js'
	import { findByUserIdApi } from '@/api/securityQuestion.js'
	import { useStore } from '@/store'

	const store = useStore()
	const router = useRouter()

	const loginForm = ref({
		username: "12345678",
		password: "12345678"
	})
	//登录
	const login = async () => {
		console.log('登录')
		const res = await loginApi(loginForm.value.username, loginForm.value.password)
		if (res.code === 0) {
			store.token = res.data.token
			console.log(res)
			await store.getLoginUser()
			console.log('跳转')
			const res1 = await findByUserIdApi(res.data.user.id)
			if (res1.data.list <= 0) {
				console.log('跳转密保页面')
				router.replace("/pages/security/question");
			} else {
				router.replace("/pages/index/index");
			}
		} else {
			console.log(res.message)
		}
	}
</script>

<style scoped>

</style>